#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;

//#define READ_FILE

struct Block
{
	int x, y;
	int height;
	bool operator<(Block& b)
	{
		if (x != b.x) { return x < b.x; }
		else { return y < b.y; }
	}
};

Block g_block[100];
int   g_dp[100];

///////////////////////////////////////
// quick sort
///////////////////////////////////////
int partition(int beg, int end)
{
	int pivotIndex = rand() / RAND_MAX * (end - beg);
	swap(g_block[beg], g_block[beg+pivotIndex]);
	
	Block b = g_block[beg];
	
	while (beg < end)
	{
		while (beg < end && !(g_block[end] < b)) { end--; }
		
		swap(g_block[beg], g_block[end]);
		
		while (beg < end && g_block[beg] < b) { beg++; }
		
		swap(g_block[beg], g_block[end]);
	}
	
	return beg;
}

void quickSort(int beg, int end)
{
	if (beg < end)
	{
		int pivot = partition(beg, end);
		quickSort(beg, pivot-1);
		quickSort(pivot+1, end);
	}
}

int calc(int n)
{
	g_dp[0] = g_block[0].height;
	int maxHeight = g_dp[0];
	
	for (int i = 1; i < n; ++i)
	{
		g_dp[i] = g_block[i].height;
		for (int j = i-1; j >= 0; --j)
		{
			if (g_block[j].x < g_block[i].x && g_block[j].y < g_block[i].y && g_dp[j] + g_block[i].height > g_dp[i])
			{
				g_dp[i] = g_dp[j] + g_block[i].height;
			}
		}
		maxHeight = (g_dp[i] > maxHeight) ? g_dp[i] : maxHeight;
	}
	
	return maxHeight;
}

int main()
{
#ifdef READ_FILE
	ifstream in("1093.input");
	if (!in) { in.open("../1093.input"); }
#else
	#define in cin
#endif

	srand((unsigned)time(NULL));
	
	int n;
	int testCase = 0;
	while ((in >> n) && n)
	{
		++testCase;
		for (int i = 0; i < n; ++i)
		{
			int a, b, c;
			in >> a >> b >> c;
			
			g_block[3*i+0].x = a >= b ? a : b;
			g_block[3*i+0].y = a < b  ? a : b;
			g_block[3*i+0].height = c;
			
			g_block[3*i+1].x = a >= c ? a : c;
			g_block[3*i+1].y = a < c  ? a : c;
			g_block[3*i+1].height = b;
			
			g_block[3*i+2].x = c >= b ? c : b;
			g_block[3*i+2].y = c < b  ? c : b;
			g_block[3*i+2].height = a;
		}
		
		quickSort(0, 3*n-1);
		int maxHeight = calc(3*n);
		
		cout << "Case " << testCase << ": maximum height = " << maxHeight << endl;
	}
	return 0;
}